﻿using AutoMapper;
using MediatR;
using T_vehicle.API.Application.Command.MaintenanceCommand;
using T_vehicle.Domain;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.MaintenanceCommandHandlers
{
    public class UpdateMaintenanceCommandHandlers:IRequestHandler<UpdateMaintenanceCommand,int>
    {
        private readonly IMaintenanceRepository maintenanceRepository;
        private readonly IMapper mapper;

        public UpdateMaintenanceCommandHandlers(IMaintenanceRepository maintenanceRepository, IMapper mapper)
        {
            this.maintenanceRepository = maintenanceRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(UpdateMaintenanceCommand request, CancellationToken cancellationToken)
        {
            var info = mapper.Map<Maintenance>(request);
            return await maintenanceRepository.UpdateAsync(info);

            //var info = new Maintenance();
            //info.MaintenanceTitle = request.MaintenanceTitle;
            //info.LicenNumber = request.LicenNumber;
            //info.MaintenanceMoney = request.MaintenanceMoney;
            //info.Head = info.Head;
            //info.MaintenanceDateNow = request.MaintenanceDateNow;
            //info.MaintenanceDate = request.MaintenanceDate;
            //info.Mileage = request.Mileage;
            //info.MaintenanceMileage = request.MaintenanceMileage;
            //info.Remark = request.Remark;
            //info.Project = request.Project;
            //return await maintenanceRepository.UpdateAsync(info);
        }
    }
}
